<?php

/**
 * Description of Question
 *
 * @author hoangle
 */
class Category {

    private $db;
    
    public function  __construct() {
        $this->db = Zend_Registry::get('db');
    }

    /**
     * @desc Get list user question by userid
     * @param <type> $userid
     * @return <array> data user question
     */
    public function getCategory() {
        try {
            $sql = "SELECT * FROM category";
            $stmt = $this->db->prepare($sql);
            $stmt->execute();
            $result = $stmt->fetchAll();
            $stmt->closeCursor();
            unset($stmt);
        }
        catch (Zend_Db_Exception $e) {
            throw new Zend_Exception($e->getMessage(), 11);
        }
        return $result;
    }
	/**
     * @desc Get list user question by userid
     * @param <type> $userid
     * @return <array> data user question
     */
    public function getCategoryById($cate_id=NULL) {
        try {
            $sql = "SELECT c.* FROM category c ";
            $sql .= "LEFT JOIN category c2 ON c2.cate_up_level = c.id ";
            if($cate_id<>NULL){               
                $where = "WHERE ( id = ".$cate_id." )";
            }
            $sql .= $where;
            $stmt = $this->db->prepare($sql);
            $stmt->execute();
            $result = $stmt->fetchAll();
            $stmt->closeCursor();
        }
        catch (Zend_Db_Exception $e) {
            throw new Zend_Exception($e);
        }
        return $result;
    }
    
}

?>
